<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.text.SimpleDateFormat,java.text.DateFormat,java.util.Date"%>
<%@ include file="/WEB-INF/common/taglib.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  	<link rel="stylesheet" href="${ctx }/static/css/Master.css"/>
	<link rel="stylesheet" href="${ctx }/static/css/Bombox.css"/>
	<script type="text/javascript" src="${ctx }/static/js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="${ctx }/static/js/jquery.autocomplete.js"></script>
	<script type="text/javascript" src="${ctx}/static/js/jquery.form.js"></script>
	<script type="text/javascript" src="${ctx}/static/js/swfobject.js"></script>
	<script type="text/javascript" src="${ctx}/static/js/jsScroller.js"></script>
	<script type="text/javascript" src="${ctx}/static/js/selectUi.js"></script>
	<script type="text/javascript" src="${ctx}/static/js/orgCommon.js"></script>
	<script type="text/javascript" src="${ctx}/static/js/layer.js"></script>
	<%-- 基础js,所有页面都需要引入此js,依赖layer.js --%>
    <script src="${ctx}/static/js/common/base.js"></script>
	<script type="text/javascript">
	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
	$(document).ready(function() {
		var orgData;
		$.ajax({    
		    url:"${ctx}/organization/findOrgList.do",    
		    data:{"orgType":3},    
		    type:"GET",    
		    cache:false,    
		    dataType:"text",
		    async:false, //默认为true 异步 
		    success:function(data) {
		    	//替换数字为字符串(js数字类型存储java long类型 64位, 过长时会丢失精度)
		    	data = data.replace(/orgId\":(\d+),/g,"orgId\":\"$1\",");
		    	data = JSON.parse(data);
		    	orgData = data;
		     } 
		});
		
		$("#orgName").autocomplete(orgData, {
			width : 300,
			matchContains : true,
			scroll : true,
			scrollHeight : 100,
			autoFill: true,
			formatItem : function(row, i, max) {
				$("#orgId").val(row.orgId);
				if(row.orgId != undefined || row.orgId != ""){
					$("#orgNameError").attr("style","display: none;");
				}
				return  row.orgName;
			},
			formatResult : function(row, i, max) {
				return row.orgName ;
			},
			formatMatch : function(row, i, max) {
				return  row.orgName;
			}
		}).result(function(event, row, formatted) {
            $("#orgId").val(row.orgId);
        });
	});
	
	function save()
	{
		var data = $("#tenementFotm").serializeJson();
		if(data.orgId == undefined || data.orgId == "")
		{
			$("#orgNameError").removeAttr("style");
		}else{
			$("#orgNameError").attr("style","display: none;");
			parent.callback(data);
			closeOpen();
		}
	}
	function closeOpen(){
   		parent.layer.close(index);
	}
	</script>
</head> 
<body> 
<form id="tenementFotm">
<input type="hidden" id="orgId" name="orgId" />
<div class="Bombox">
	<div class="BombCon">
		<div class="BombQZ_con">
			<div class="BombQZ_top">
				<div class="QZ_search"><input id="orgName" name="orgName" placeholder="输入关键字查找" type="text" style="width: 300px;"/></div>
				<div id="orgNameError" style="display: none;"><label style="color: red;">没有查询到相应的数据</label></div>
			</div>
			<div class="combtn layerbtn" style="margin: 200px 100px 0 0 "><a href="javascript:save();">确定</a><a href="javascript:closeOpen(0);">取消</a></div>
		</div>
	</div>
</div>

</form>
</body> 
</html>
